package com.rxt.controller;


import com.rxt.common.result.Result;
import com.rxt.model.domain.OShoppingCart;
import com.rxt.model.vo.CartVo;
import com.rxt.model.vo.ProdNumVo;
import com.rxt.service.IOShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 周梓文
 * @since 2023-08-24
 */
@Api(tags = "购物车模块")
@Slf4j
@RestController
@RequestMapping("/oShoppingCart")
public class OShoppingCartController {

    @Autowired
    private IOShoppingCartService shoppingCartService;

    @ApiOperation("加入购物车")
    @GetMapping("/addCart")
    public Result addCart(CartVo cartVo) {
        shoppingCartService.addCart(cartVo);
        return Result.ok();
    }

    @ApiOperation("查询购物车")
    @GetMapping("/findCart")
    public Result findCart() {
        List<OShoppingCart> shoppingCarts = shoppingCartService.findCart();
        return Result.ok(shoppingCarts);
    }

    @ApiOperation("购物车删除")
    @DeleteMapping
    public Result delete(@RequestParam List<Long> CartIds) {
        shoppingCartService.deleteBatch(CartIds);
        return Result.ok();
    }

    @ApiOperation("购物车商品数目更新")
    @PostMapping("/updateNumber")
    public Result updateNumber(@RequestBody ProdNumVo prodNumVo) {
        shoppingCartService.updateNumber(prodNumVo);
        return Result.ok();
    }

}

